///////////////////////////////////////////
// FeedBack mod.
// Book AJAX & PHP
// Coded by Skalden Russell
//

var xmlHTTP = createXmlHttpRequestObject();

function createXmlHttpRequestObject()
{
	var xmlHTTP;
	try 
	{
		xmlHTTP = new XMLHttpRequest();
	}
	catch(e)
	{
		var XmlHttpVersions = new Array( "MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0",
			"MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP" );
		for(var i=0; i < XmlHttpVersions.length && !xmlHTTP; i++)
		{
			try
			{
				xmlHTTP = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch(e){}
		}
	}
	
	if(!xmlHTTP)
		alert("Error: Creating XMLHttpRequest.");
	else
		return xmlHTTP;
} 

function process( TicketId )
{
	if(xmlHTTP)
	{
		try
		{
			if(xmlHTTP.readyState == 4 || xmlHTTP.readyState == 0)
			{
				xmlHTTP.open("GET", "engine/ajax/ajax_feedback.php?id=" + TicketId, true);
				xmlHTTP.onreadystatechange = handleServerResponse;
				xmlHTTP.send(null);
			}
			else
				setTimeout('process()', 1000);
				
		}
		catch(e)
		{
			alert("Error: Connecting error:\n" + e.toString());
		}
	}
}

function handleServerResponse()
{
	if(xmlHTTP.readyState == 4)
	{
		if(xmlHTTP.status == 200)
		{
			xmlResponse = xmlHTTP.responseXML;
			xmlDocumentElement = xmlResponse.documentElement;
			receiveMessage = xmlDocumentElement.firstChild.data;
			document.getElementById( "messageid" ).innerHTML = '<i>' + receiveMessage + '</i>';
		}
		else
		{
			alert("Error: Transaction with server:" + xmlHTTP.statusText);
		}
	}
}